<?php
class Customer_model extends MY_Model{

	function __construct()
	{
		parent::__construct();
		$this->_table		=	'customers';
		$this->primary_key	=	'id';
	}
	
	function get_limit($limit = 10, $offset = 0, $like = array())
	{
		if($like){
			$this->db->like($like);
		}
		//die($_SESSION['_user']['user_id']);
		if($_SESSION['_user']['group_id'] !=1){
			$this->db->where('create_by',$_SESSION['_user']['user_id']);
		}
		$q	=	$this->db->select()->from($this->_table)->order_by('date_create DESC')->limit($limit,$offset)->get();
		//echo $this->db->last_query();
		$result['rows']		=	$q->result();
		
		if($_SESSION['_user']['group_id'] !=1){
			$this->db->where('create_by',$_SESSION['_user']['user_id']);
		}
		if($like){
			$this->db->like($like);
		}
		$q	=	$this->db->select('count(id) as cnt')->from($this->_table)->get();
		$result['num_rows']	=	$q->row()->cnt;
		$this->db->cache_delete_all();
		return $result;
	}
	
	function get_by_id_array($id = null)
	{
		$customer	=	$this->db->select('')->from($this->_table)->where('id',$id)->get()->row_array();
		return $customer;
	}
}